package handler

import (
	"context"
	frontdesk "frontdesk/proto/frontdesk"
	srv1 "frontdesk/proto/srv1"
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/client"
)

type handler struct {
	Client client.Client
}

func Handler(SrvClient client.Client) frontdesk.FrontdeskHandler {
	return &handler{Client: SrvClient}
}

func (h *handler) Simu(ctx context.Context, request *srv1.Request) (response *srv1.Response, err error) {
	cli := srv1.NewSrv1Service("go.micro.srv.srv1", h.Client)
	response, err = cli.Simu(ctx, request)
	return response, err
}

// 发布消息Request，topic为SM.send
func PubRequest(ctx context.Context, event *frontdesk.Request) error {
	srv := micro.NewService()

	pub := micro.NewPublisher("simu", srv.Client())

	if err := pub.Publish(ctx, event); err != nil {
		return err
	}
	return nil
}
